# -*- coding:utf-8 -*-
from django.http import HttpResponse
from musicmovie.doubanmovie.newmovie import getnewmovie
from musicmovie.models import Movie
import simplejson

def dbcrawler(request):
    """
    check exist using the doubanid
    """
    movies = getnewmovie()
    for movie in movies:
        c = Movie.all().filter('doubanid = ',movie['id']).count()
        if c == 0:
            tmpm = Movie()
            tmpm.name = movie['name'].decode("utf-8")
            tmpm.doubanid = movie['id']
            tmpm.jsondesp = simplejson.dumps(movie).decode("utf-8")
            tmpm.save()
        elif c > 1:
            logging.error("a doubanid corresponde to more than one movie item")
    dic = {}
    dic['status'] = "1"
    return HttpResponse(simplejson.dumps(dic))


def querysuggest(request):
    """
    input a prefix and return the similar query()
    """

def approveAdd(request):
    """
    admin only
    approve User Action
    """

def denyAdd(request):
    """
    admin only
    deny UserAction
    """

def getLinkGraph(request):
    """
    get link graph of a movie for related music
    """

